<?php

session_start();

include_once "src/controller/blmanagement/UserAccountManagement.php";
include_once "src/model/User.php";
include_once "src/misc/ClientReponseGenerator.php";

try {

    $userAccounts = UserAccountManagement::getAllUsers();

    

    $items = "";
    $usersCount = count($userAccounts);
    for ($i = 0; $i < $usersCount; $i++) {
        $user = $userAccounts[$i];
        if ($user->getEmail() != $_SESSION["email"]) {
           $items .= "{\"id\":\"".$user->getUserId()."\", \"username\":\"".$user->getName()."\"}";
            if (($usersCount > 1) && (($i + 1) < $usersCount)) {
                $items .= ",";
            }
        }
    }

    echo ClientReponseGenerator::jsonResponse(1, $items, "", "");

} catch (Exception $e) {
    echo ClientReponseGenerator::simpleJsonResponse(0, "GetAllUserAccountsException", "");
}

?>
